#include <stdio.h>

int main()
{
    char *filename = "test2.txt";
    FILE *myfile = fopen(filename,"a+");
    if(myfile==NULL){
        printf("文件打开失败\r\n");
    }else{
        printf("文件打开成功\r\n");
    }

    char name[10];
    int age;
    while(scanf(myfile,"%s %d\n",name,&age)>=2){
        printf("姓名：%s,年龄：%d\n",name,age);
    }
    int result = fclose(myfile);
    if(result!=0){
        printf("文件关闭失败%d\r\n",result);
    }else{
        printf("文件打开成功%d\r\n",result);
    }
    return 0;
}